package kr.hkit.androidcomplete03.ch29.common;

import java.util.ArrayList;

import kr.hkit.androidcomplete03.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter {
	Context context;
	int layout;
	ArrayList<Item> itemList;
	LayoutInflater inflater;

	public MyAdapter(Context context,  ArrayList<Item> itemList) {
		this.context = context;
		//this.layout = layout;
		this.itemList = itemList;
		this.inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position).getItemName();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(R.layout.itemrow, parent, false);
		}
		
		TextView itemName = (TextView) convertView.findViewById(R.id.itemName);
		TextView itemMaker = (TextView) convertView.findViewById(R.id.makerName);
		TextView itemPrice = (TextView) convertView.findViewById(R.id.itemPrice);
		
		itemName.setText(itemList.get(position).getItemName());
		itemMaker.setText(itemList.get(position).getItemMaker());
		itemPrice.setText(String.valueOf(itemList.get(position).getItemPrice()));
		
		return convertView;
	}

}
